package com.jxust.hr.dao;

import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description 部门主管的表
 *
 **/
@Mapper
public interface ManagerMapper {

    /**
     * @Description
     *    通过用户名来查找 '今天' 的待办事务
     *    LIMIT 3
     **/
    @Select({"SELECT `tag`,`todo` FROM hr_todo WHERE username = #{username} and DATE_FORMAT(`time`,'%y%m%d') = DATE_FORMAT( NOW() ,'%y%m%d') ORDER BY `id` DESC LIMIT 3"})
    List<Map<String,Object>> getTodos(@Param("username")String username);

    /**
     * @Description
     *  插入hr_todo表中 待办事务的数据
     **/
    @Insert({"INSERT INTO hr_todo(`username`,`create_date`,`time`,`tag`,`todo`) VALUES (#{username},NOW(),#{time},#{tag},#{todo});"})
    int setTodo(@Param("username")String username,
                @Param("time")String time,
                @Param("tag")String tag,
                @Param("todo")String todo);

    /**
     * @Description
     *   查询所有员工的数量
     **/
    @Select({"SELECT COUNT(*) FROM employee"})
    int selectEmployeeSum();

    /**
     * @Description
     *   通过传过来的时间,和type类型,返回对应的具体人数
     **/
    @Select({"SELECT COUNT(*) FROM `hr_attendance` WHERE DATE_FORMAT(DATA,'%y%m%d')=DATE_FORMAT( #{date} ,'%y%m%d') AND TYPE= #{type} "})
    int selectEmployeeTypeCount(@Param("date")Date date,
                                @Param("type")String type);


    /**
     * @Description
     *    查找本周缺勤人的详细信息
     **/
    List<Map<String,Object>> selectAttendanceInfo();

    /**
     * @Description
     *  查找所有部门
     **/
    @Select({"select DName from department"})
    List<String> getPositions();


    /**
     * @Description
     *
     * @return 返回符合要求的员工信息
     * @param name 员工名字
     * @param position 员工职位
     * @param limit 页面限制展示的条数
     * @param offset 当前第几页
     **/
    List<Map<String,Object>> getMembers(@Param("name")String name,
                                        @Param("position")String position,
                                        @Param("limit")int limit,
                                        @Param("offset")int offset);

    /**
     * @Description
     *    通过员工ID返回,员工信息
     **/
    Map<String,Object> getEmployeeInfoById(@Param("employeeId")String employeeId);

    /**
     * @Description
     *  通过员工ID 和 考勤类型type("迟到","缺勤","早退")
     *  返回对应类型的数量
     **/
    @Select({"SELECT COUNT(*) AS num FROM `hr_attendance` WHERE employee_id =#{employeeId} AND `type`=#{type} GROUP BY `type`;"})
    Integer getAttendanceNumById(@Param("employeeId")String employeeId,
                                 @Param("type")String type);

    /**
     * @Description
     *  通过用户ID查找员工的一些在职表现
     *  绩效完成情况
     *  出勤状况
     *  ....
     *
     *  ORDER BY `date` DESC LIMIT 1 返回" 一条" 符合条件的 "最新" 时间数据
     **/
    @Select({"SELECT * FROM  employee_comment WHERE employee_id=#{employeeId} ORDER BY `date` DESC LIMIT 1 "})
    Map<String,Object> selectEmployeePositionInfo(@Param("employeeId")String employeeId);


    /**
     * @Description
     *  查询出现在
     **/
    @Select({"SELECT id as Id,`name` FROM employee ORDER BY id  LIMIT 10;"})
    List<Map<String,Object>> getEmployeeList();

    /**
     * @Description
     *  插入数据,成功返回 1
     **/
    @Insert({"insert into hr_task(task,start_time,end_time,executors,time) values (#{task},#{start_time},#{end_time},#{executors},NOW())"})
    int setTasks(@Param("task")String task,
                 @Param("start_time")String start_time,
                 @Param("end_time")String end_time,
                 @Param("executors")String executors);


    /**
     * @Description
     *  查询  hr_task 绩效考核页面的表数据
     **/
    @Select({"select * from hr_task ORDER BY `id` DESC LIMIT 5"})
    List<Map<String,Object>> getTasks();


    /**
     * @Description
     *    通过id 更新绩效考核的完成度
     **/
    @Update({"UPDATE  hr_task SET `completion`=#{completion} WHERE id=#{id} "})
    int setTaskCompletion(@Param("id")Integer id,
                          @Param("completion")String completion);


    /**
     * @Description
     *  得到员工评价页面的信息
     **/
    List<Map<String,Object>> getEvaluationList();

    /**
     * @Description
     *    将数据 插入hr_evaluation表中
     **/
    @Insert({"insert into hr_evaluation(`employee_id`,`time`,`working_performance`,`violation`,`contribution`,`others`) " +
            "values(#{employeeId} ,NOW(),#{working_performance},#{violation},#{contribution},#{others} )"})
    int setEvaluation( @Param("employeeId")String employeeId,
                       @Param("working_performance")String working_performance,
                       @Param("violation")String violation,
                       @Param("contribution")String contribution,
                       @Param("others")String others);



    /**
     * @Description
     *  通过用户id查找,所有的用户信息
     **/
    @Select({"select * from employee where id = #{employeeId}"})
    Map<String,Object> getEmployeeAllInfoById( @Param("employeeId")String employeeId);
    /**
     * @Description
     *    通过id查找员工当前就职的公司
     **/
    Map<String,Object> getCurrentCompany( @Param("employeeId")String employeeId);

    /**
     * @Description
     *  通过员工id查找,该员工过去呆过的公司
     **/
    List<Map<String,Object>> getLastCompanies( @Param("employeeId")String employeeId);

}
